home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000074_icon-group-sender _Wed Mar 31 09:27:26 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  6KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id JAA09430
  4.     for icon-group-addresses; Wed, 31 Mar 1999 09:27:18 -0700 (MST)
  5. Message-Id: <199903311627.JAA09430@baskerville.CS.Arizona.EDU>
  6. Date: Wed, 31 Mar 1999 00:13:29 -0400 (AST)
  7. From: Larry Bezeau <bezeau@unb.ca>
  8. X-Sender: bezeau@sol.sun.csd.unb.ca
  9. To: Icon list <icon-group@optima.CS.Arizona.EDU>
  10. Subject: Re: Problem reading binary file
  11. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  12. Status: RO
  13.  
  14. Steve,
  15.  
  16. >I am using MS-DOS Icon 9.1 to read a binary file.  After reading 6
  17. >characters, the program apparently quits reading.  I have attached the
  18. >relevant portion of the code:
  19. >
  20.         I encountered this problem myself sometime ago.  To overcome
  21. it you must open the file in unstranslated mode as shown below.
  22. Note the "u" in the open statement.  A "t" in the same position means
  23. translated but this is the default if neither is specified.
  24.  
  25.   in  := open(args[1],"ru") | stop("Unable to open ",args[1])
  26.  
  27. This will allow your program to read the file character by character
  28. without having to worry about whether the character is an end of file
  29. character or a line-ending character.  In general, if you are reading
  30. a file with reads, it should be opened in untranslated mode and if
  31. you are reading it with read it should be opened in translated mode.
  32. To put it another way, if the file is being used as a text file it
  33. should be opened in translated mode but if it is being used as a
  34. binary file it should be opened in untranslated mode.
  35.  
  36.                                     Larry     Bezeau@UNB.Ca
  37.  
  38. >-------------------------- Code ------------------------------
  39. >procedure main(args)
  40. >#
  41. >  cnt := 0
  42. >  out := open(args[2],"w") | stop("Unable to open ",args[2])
  43. >  while character := reads(in,1) do {
  44. >     write(character," -->", ord(character))
  45. >     cnt := cnt+1
  46. >    }
  47. >  close(in,out)
  48. >  write(cnt," characters transferred")
  49. >end
  50. >-----------------------End of Code-------------------------
  51. >
  52. >I invoke the program with:
  53. >
  54. >word r99-0059.doc r99-0059.txt
  55. >
  56. >
  57. >I get output of (some unprintable characters are represent by _):
  58. >
  59. >- -->208
  60. >- -->207
  61. > -->17
  62. >_ -->224
  63. >∩┐╜ -->161
  64. >_ -->177
  65. >6 characters transferred
  66. >
  67. >
  68. >Any ideas?
  69. >
  70. >Thanks in advance.
  71. >
  72. >
  73. >-- Steve
  74. >
  75. >
  76. >______________________________________________________
  77. >
  78. >Steve Graham
  79. >Laboratory Corporation of America (LabCorp)
  80. >12160 Abrams Road, Suite 601
  81. >Dallas, Texas 75243
  82. >
  83. >E-mail: graham@cowboy.biomed.com
  84. >Phone:  972.643.6124  (direct to desk)
  85. >        972.437.5255 ext 5224
  86. >FAX:    972.454.1040
  87. >_______________________________________________________
  88. >
  89. >From icon-group-sender@baskerville.CS.Arizona.EDU  Tue Mar 30 18:42:50 1999
  90. >Date: Tue, 30 Mar 1999 16:04:23 -0600
  91. >From: Steve Graham <graham@cowboy.biomed.com>
  92. >Subject: [Fwd: Problem reading binary file]
  93. >Status: O
  94. >X-Status:
  95. >X-Keywords:
  96. >X-UID: 2
  97. >
  98. >Hello again.
  99. >
  100. >Turns out that the problem with this was that the 7th character was an
  101. >ASCII 26 (^Z) and Icon would not read any further than that.  I created
  102. >a 2nd file with a ^Z in a different position and got a similar result.
  103. >This is despite the fact that there were over 25,000 characters
  104. >following the Control Z.
  105. >
  106. >So, my question is:  Why does Icon stop reading when it hits a ^Z?  I
  107. >can kind of understand this if I were reading a text file; but I was
  108. >specifically using reads() because this is a binary file?  Should not
  109. >reads() support all 256 ASCII codes and only stop reading when there are
  110. >REALLY no more characters to read?  I ended up using another language,
  111. >which was significantly harder for me, to read the binary characters.
  112. >
  113. >In Icon's defense, I notice that when I TYPE the above-mentioned 2nd
  114. >file, I only see the characters occurring prior to the ^Z.  And I do not
  115. >want it to appear that I am questioning Icon's usefulness.  It is
  116. >normally one of the 1st languages I choose for utilities of this type.
  117. >
  118. >Comments?
  119. >
  120. >
  121. >Steve Graham
  122. >
  123. >===
  124. >
  125. >Steve Graham wrote:
  126. >>
  127. >> Hello.
  128. >>
  129. >> I am using MS-DOS Icon 9.1 to read a binary file.  After reading 6
  130. >> characters, the program apparently quits reading.  I have attached the
  131. >> relevant portion of the code:
  132. >>
  133. >> -------------------------- Code ------------------------------
  134. >> procedure main(args)
  135. >> #
  136. >>   cnt := 0
  137. >>   in  := open(args[1],"r") | stop("Unable to open ",args[1])
  138. >>   out := open(args[2],"w") | stop("Unable to open ",args[2])
  139. >>   while character := reads(in,1) do {
  140. >>      write(character," -->", ord(character))
  141. >>      cnt := cnt+1
  142. >>     }
  143. >>   close(in,out)
  144. >>   write(cnt," characters transferred")
  145. >> end
  146. >> -----------------------End of Code-------------------------
  147. >>
  148. >> I invoke the program with:
  149. >>
  150. >> word r99-0059.doc r99-0059.txt
  151. >>
  152. >> I get output of (some unprintable characters are represent by _):
  153. >>
  154. >> - -->208
  155. >> - -->207
  156. >>  -->17
  157. >> _ -->224
  158. >> ∩┐╜ -->161
  159. >> _ -->177
  160. >> 6 characters transferred
  161. >>
  162. >> Any ideas?
  163. >>
  164. >> Thanks in advance.
  165. >>
  166. >> -- Steve
  167. >>
  168. >> ______________________________________________________
  169. >>
  170. >> Steve Graham
  171. >> Laboratory Corporation of America (LabCorp)
  172. >> 12160 Abrams Road, Suite 601
  173. >> Dallas, Texas 75243
  174. >>
  175. >> E-mail: graham@cowboy.biomed.com
  176. >> Phone:  972.643.6124  (direct to desk)
  177. >>         972.437.5255 ext 5224
  178. >> FAX:    972.454.1040
  179. >> _______________________________________________________
  180. >
  181.  
  182.